;(function(){
var db = require("../db/index");
var UserCon = require("./_con");
var BusCon = require("../bus/_con");
var GoodsCon = require("../goods/_con");
var AchCon = require("../ach/_con");
var PayAchCon = require("../pay_ach/_con");
var CommentCon = require("../comment/_con");
var config = require("../_include/config");
var data_cut = require("../_include/data_cut");
var $Array = require("../_include/$.Array");

var makeCommenter = {
	
	//获取详细评论列表
	getComments:function(num,page){
		var comments = this.comments||(this.comments=[]);
		comments = data_cut.page(comments,num,page);
		comments.forEach(function(comment_id,index) {
			comments[index] = CommentCon.get(comment_id);
		});
		return comments;
	},
	//评价商品
	commentGoods:function(goods_id,content,reply_id){
		try{
			var goods = GoodsCon.get(goods_id);
			if (!goods) {
				throwCusError("找不到指定商品")
				return
			}
			var comments_info = {
				type:this.type,
				commenter_id:this._id,
				goods_id:goods_id,
				content:content,
				reply_id:reply_id
			};
			var comment = new CommentCon();
			goods.addComment(comment._id);
		}catch(e){
			console.error(e)
		}
	},
	//删除评论
	removeComment:function(comment_id){
		var comments = this.comments||(this.comments=[]);
		var index = comments.indexOf(comment_id);
		if (index===-1) {
			throwCusError("评论不属于指定的对象")
		}else{
			var comment = CommentCon.get(comment_id);
			if (comment) {
				comment.remove();
			}else{
				throwCusError("找不到指定评论")
			}
		}
	},
	//获取回复
	getReplys:function(){
		
	}
}
module.exports = {
	forConstructor:function(constructor) {
		for(var methodName in makeCommenter){
			constructor.prototype[methodName] = makeCommenter[methodName];
		}
	},
	forInstance:function(instance){
		//评论
		instance.comments = [];
		//收到的回复
		instance.replys = [];
	}
};
}());